/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.coupon.core.domain;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.lang.Assert;
import info.peigen.hotpot.common.core.enums.YesOrNo;
import info.peigen.hotpot.common.core.result.ResultCode;
import info.peigen.hotpot.common.service.base.exception.BusinessException;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;
import lombok.experimental.SuperBuilder;

/**
 * <b>(CouponExpiryDate)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/6/28
 */
@SuperBuilder
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
@Accessors(chain = true)
public class CouponExpiryDate {
    @Builder.Default
    YesOrNo expiry = YesOrNo.Y;
    /** 固定时间：XX年XX月XX日至XX年XX月XX日 */
    DateTime stableDate;
    /** 浮动时间：领取后X天XX小时内有效 */
    DateTime floatingDate;

    public void check() {
        if (expiry == YesOrNo.Y) {
            Assert.notEmpty(new DateTime[]{stableDate, floatingDate}, () -> new BusinessException(ResultCode.FAILURE, "stableDate,floatingDate 不得同时为空!"));
        }
    }
}